<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>冒泡排序</title>
</head>

<body>
    <script>
        var arr = [9, 7, 4, 1, 3, 2, 5, 6, 8, 1, 2, 4]
        for (let i = 0; i < arr.length; i++) {//外层循环
            for (let index = 0; index < arr.length - i - 1; index++) {//内层循环 交换的次数
                //内部交换变量
                if (arr[index] > arr[index + 1]) {
                    var temp = arr[index]
                    arr[index] = arr[index + 1]
                    arr[index + 1] = temp
                }
            }
        }
        console.log(arr);

    </script>
</body>

</html>